/*************************************************************************

    tree.h

    Version 7.51 

    This module contains the parse tree declarations

    Copyright (c) 2002-2014  SLK Systems, all rights reserved.
    
*************************************************************************/

#ifndef _SLKTREE_C_H
#define _SLKTREE_C_H

#include "SlkToken.h"
#include "SlkConstants.h"

#define PRIVATE static
#define PUBLIC
#define INSTANCE_METHOD static

typedef struct _node  {
    slk_size_t    token;
    float         value;
    struct 
    _node   *parent,        // parent is the lhs of the production
            *child,         // first symbol on rhs of production
            *sibling,       // rest of the parent production is siblings
            *left_sibling;  // to go backwards
} node_t;

#define STACKSIZE   256 

typedef struct _stack
{
    node_t  **top ,
            **end ,
             *start [ STACKSIZE ];
} stack_t;

// ------------------------------------------------------------------------
// tree_t
// 
// A struct to avoid public names, enable initialization, and
// provide instance data so it is reentrant.
// The struct only goes away when its declaration goes out of scope. 
// Any other cleanup should be in a release() method called explicitly.
// ------------------------------------------------------------------------

#undef  SELF    
#define SELF    struct _tree

typedef struct _tree
{
    node_t    *root;
    int        display;
    peeker_t  *peeker; 
    stack_t    parse_stack;

    void  (*reduce) ( SELF *id, slk_size_t production_number );
    void  (*predict) ( SELF *id, slk_size_t production_number );

    void  (*show_tree) ( SELF *id );
    void  (*show_parse_derivation) ( SELF *id );

} tree_t, SlkTree;

#define reduce(self,a)           (*self).reduce(self,a)
#define predict(self,a)          (*self).predict(self,a)

#define show_tree(self)          (*self).show_tree(self)
#define show_parse_derivation(self)   (*self).show_parse_derivation(self)

PUBLIC   
void
InitializeTree ( tree_t    *tree,
                 int        display,
                 peeker_t  *peeker );

#endif

